package com.imagesystem.web.controller.system;

import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.imagesystem.common.annotation.Log;
import com.imagesystem.common.enums.BusinessType;
import com.imagesystem.system.domain.EndoscopeInfo;
import com.imagesystem.system.service.IEndoscopeInfoService;
import com.imagesystem.common.core.controller.BaseController;
import com.imagesystem.common.core.domain.AjaxResult;
import com.imagesystem.common.utils.poi.ExcelUtil;
import com.imagesystem.common.core.page.TableDataInfo;

/**
 * 内镜信息Controller
 *
 * @author ruoyi
 * @date 2024-10-11
 */
@Controller
@RequestMapping("/system/info")
public class EndoscopeInfoController extends BaseController {
    private String prefix = "system/info";

    @Autowired
    private IEndoscopeInfoService endoscopeInfoService;

    @RequiresPermissions("system:info:view")
    @GetMapping()
    public String info() {
        return prefix + "/info";
    }

    /**
     * 查询内镜信息列表
     */
    @RequiresPermissions("system:info:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(EndoscopeInfo endoscopeInfo) {
        startPage();
        List<EndoscopeInfo> list = endoscopeInfoService.selectEndoscopeInfoList(endoscopeInfo);
        return getDataTable(list);
    }

    /**
     * 导出内镜信息列表
     */
    @RequiresPermissions("system:info:export")
    @Log(title = "内镜信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(EndoscopeInfo endoscopeInfo) {
        List<EndoscopeInfo> list = endoscopeInfoService.selectEndoscopeInfoList(endoscopeInfo);
        ExcelUtil<EndoscopeInfo> util = new ExcelUtil<EndoscopeInfo>(EndoscopeInfo.class);
        return util.exportExcel(list, "内镜信息数据");
    }

    /**
     * 新增内镜信息
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存内镜信息
     */
    @RequiresPermissions("system:info:add")
    @Log(title = "内镜信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(EndoscopeInfo endoscopeInfo) {
        return toAjax(endoscopeInfoService.insertEndoscopeInfo(endoscopeInfo));
    }

    /**
     * 修改内镜信息
     */
    @RequiresPermissions("system:info:edit")
    @GetMapping("/edit/{endoscopeId}")
    public String edit(@PathVariable("endoscopeId") String endoscopeId, ModelMap mmap) {
        EndoscopeInfo endoscopeInfo = endoscopeInfoService.selectEndoscopeInfoByEndoscopeId(endoscopeId);
        mmap.put("endoscopeInfo", endoscopeInfo);
        return prefix + "/edit";
    }

    /**
     * 修改保存内镜信息
     */
    @RequiresPermissions("system:info:edit")
    @Log(title = "内镜信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(EndoscopeInfo endoscopeInfo) {
        return toAjax(endoscopeInfoService.updateEndoscopeInfo(endoscopeInfo));
    }

    /**
     * 删除内镜信息
     */
    @RequiresPermissions("system:info:remove")
    @Log(title = "内镜信息", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(endoscopeInfoService.deleteEndoscopeInfoByEndoscopeIds(ids));
    }


    /**
     * 获取所有内镜信息
     */
    @RequiresPermissions("system:info:getAllEndoscope")
    @Log(title = "获取所有内镜信息", businessType = BusinessType.INSERT)
    @PostMapping("/getAllEndoscope")
    @ResponseBody
    public AjaxResult getAll(EndoscopeInfo endoscopeInfo) {
        endoscopeInfoService.getAllEndoscope(endoscopeInfo);
        return toAjax(true);
    }
}
